package demo.icanci.pattern.singleton;

/**
 * 枚举实现 单例
 *
 * @author icanci
 * @date Created in 2021/02/06 00:42
 * @version 1.0
 */
public class EnumStarvingSingleton {
    /**
     * 枚举
     */
    private enum ContainerHolder {
                                  HOLDER;

        private EnumStarvingSingleton instance;

        ContainerHolder() {
            instance = new EnumStarvingSingleton();
        }
    }

    /**
     * 私有化构造器
     */
    private EnumStarvingSingleton() {

    }

    /**
     * 获取单例对象
     * @return
     */
    public static EnumStarvingSingleton getInstance() {
        return ContainerHolder.HOLDER.instance;
    }
}
